package com.mc.code.service.Impl;

import com.mc.code.entity.CodeItems;
import com.mc.code.mapper.ItemsMapper;
import com.mc.code.service.ItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemsImpl implements ItemsService {
    @Autowired
    private ItemsMapper itemsMapper;

    @Override
    public List<CodeItems> items(int num) {
        return itemsMapper.items(num);
    }

    @Override
    public List<CodeItems> itemsDetails(int itemNo) {
        return itemsMapper.itemsDetails(itemNo);
    }

    //    查询当前项目阶段
    @Override
    public int itemsStageNum(Integer itemNo) {
        return itemsMapper.itemsStageNum(itemNo);
    }

    //    查看当前项目总阶段
    @Override
    public int itemsTotalNum(Integer itemNo) {
        return itemsMapper.itemsTotalNum(itemNo);
    }

    //    返回项目最大id数
    @Override
    public int itemsEndNo() {
        return itemsMapper.itemsEndNo();
    }

    //    返回是否收藏项目数
    @Override
    public Integer collection(int userNo, int itemNo) {
        return itemsMapper.collection(userNo, itemNo);
    }

    //    取消收藏项目
    @Override
    public void delCollection(int itemNo, int userNo) {
        itemsMapper.delCollection(itemNo, userNo);
    }
    @Override
    public void addCollection(int itemNo, int userNo) {
        itemsMapper.addCollection(itemNo, userNo);
    }
    @Override
    public int collectionNum(Integer itemNo) {
        return itemsMapper.collectionNum(itemNo);
    }
    @Override
    public void releaseProject(CodeItems codeItems) {
        itemsMapper.releaseProject(codeItems);
    }

//    我的收藏
    @Override
    public List<CodeItems> collectItems(String userNo, int currentPage, int pageCount) {
        return itemsMapper.collectItems(userNo,(currentPage - 1) * pageCount,pageCount);
    }

    //    我发布的项目
    @Override
    public List<CodeItems> releaseItems(String userNo, int currentPage, int pageCount) {
        return itemsMapper.releaseItems(userNo,(currentPage - 1) * pageCount,pageCount);
    }

    @Override
    public void updateItemDid(Integer itemNo, Integer start) {
        itemsMapper.updateItemDid(itemNo, start);
    }

    @Override
    public void delItems(Integer itemNo) {
        itemsMapper.delItemsPratake(itemNo);
        itemsMapper.delItemsItems(itemNo);
        itemsMapper.delItemscollection(itemNo);
    }

    @Override
    public void insertPartake(String userNo, Integer itemNo) {
        itemsMapper.insertPartake(userNo,itemNo);
    }

    @Override
    public Integer selectPartake(String userNo, Integer itemNo) {
        return itemsMapper.selectPartake(userNo,itemNo);
    }

    @Override
    public void delPartake(String userNo, Integer itemNo) {
        itemsMapper.delPartake(userNo,itemNo);
    }

    @Override
    public List<CodeItems> prtakeItems(String partakeNo) {
        return itemsMapper.partakeItems(partakeNo);
    }

    @Override
    public List<CodeItems> findItems(int currentPage, int pageCount, String itemType, String itemDid) {
        return itemsMapper.findItems((currentPage - 1) * pageCount,pageCount,itemType,itemDid);
    }

    @Override
    public int getTotalPage(int pageCount, String itemType, String itemDid) {
        Integer total =itemsMapper.getTotalPage(itemType,itemDid);
        return (total - 1) / pageCount + 1;
    }

    @Override
    public int getMyRealseTotalPage(int pageCount, String userNo) {
        Integer total =itemsMapper. getMyRealseTotalPage(userNo);
        return (total - 1) / pageCount + 1;
    }

    @Override
    public int getMyCollectionTotalPage(int pageCount, String userNo) {
        Integer total = itemsMapper.getMyCollectionTotalPage(userNo);
        return (total - 1) / pageCount + 1;
    }


}
